<template>
  <div class="app-container">
    <el-form :model="queryParams1" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="受贿行为查询" prop="caseName">
        <el-input
          v-model="queryParams1.caseName"
          placeholder="请输入搜索关键字（公司名、注册号、统一社会信用代码）"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="judgeList1" @selection-change="handleSelectionChange">
      <el-table-column label="主键" align="center" prop="id" v-if="false"/>
      <el-table-column label="文书标题" align="center" prop="caseName" />
      <el-table-column label="案由" align="center" prop="caseReason" />
      <el-table-column label="案号" align="center" prop="caseNo" />
      <el-table-column label="案件类型" align="center" prop="caseType" />
      <el-table-column label="案件金额" align="center" prop="amount" />
      <el-table-column label="是否原告" align="center" prop="isProsecutor" />
      <el-table-column label="是否被告" align="center" prop="isDefendant" />
      <el-table-column label="裁判结果" align="center" prop="judgeResult" />
      <el-table-column label="裁判日期" align="center" prop="judgeDate" />
      <el-table-column label="发布日期" align="center" prop="publishDate" />
      <el-table-column label="当事人信息" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="clickDetail(scope.row)"
          >查看详情</el-button>
      </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total1>0"
      :total="total1"
      :page.sync="queryParams1.pageNum"
      :limit.sync="queryParams1.pageSize"
      @pagination="getList1"
    />
    <br>
    <br>
    <el-button type="text" @click="clickOne">历史记录</el-button>
    <div v-if="flag">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:judge:remove']"
          >删除</el-button>
        </el-col>
      </el-row>
    <el-table v-loading="loading" :data="judgeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" v-if="false"/>
      <el-table-column label="搜索关键词" align="center" prop="searchKey" />
      <el-table-column label="文书标题" align="center" prop="caseName" />
      <el-table-column label="案由" align="center" prop="caseReason" />
      <el-table-column label="案号" align="center" prop="caseNo" />
      <el-table-column label="案件类型" align="center" prop="caseType" />
      <el-table-column label="案件金额" align="center" prop="amount" />
      <el-table-column label="是否原告" align="center" prop="isProsecutor" />
      <el-table-column label="是否被告" align="center" prop="isDefendant" />
      <el-table-column label="裁判结果" align="center" prop="judgeResult" />
      <el-table-column label="裁判日期" align="center" prop="judgeDate" />
      <el-table-column label="发布日期" align="center" prop="publishDate" />
      <el-table-column label="当事人信息" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="clickDetail(scope.row)"
          >查看详情</el-button>
      </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </div>
    <!-- 当事人信息，关联裁判文书信息表 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-table v-loading="loading" :data="judgeDetailList" >
      <el-table-column label="主键" align="center" prop="id" v-if="false"/>
      <el-table-column label="当事人名称" align="center" prop="name" />
      <el-table-column label="案件角色" align="center" prop="roleType" />
      <el-table-column label="案件声明" align="center" prop="statement" />
      </el-table>
      <pagination
      v-show="total2>0"
      :total="total2"
      :page.sync="queryParams2.pageNum"
      :limit.sync="queryParams2.pageSize"
      @pagination="clickDetail"
    />
    </el-dialog>
  </div>
</template>

<script>
import { listJudge, getJudge, delJudge, searchName,getJudgeDetail } from "@/api/system/judge";

export default {
  name: "Judge",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: false,
      flag: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total1: 0,
      total2: 0,
      // 裁判文书信息表格数据
      judgeList: [],
      judgeList1: [],
      judgeDetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        caseName: undefined,
        searchKey: undefined,
        caseReason: undefined,
        caseNo: undefined,
        caseType: undefined,
        amount: undefined,
        isProsecutor: undefined,
        isDefendant: undefined,
        judgeResult: undefined,
        judgeDate: undefined,
        publishDate: undefined,
      },
      // 表单参数
      form: {},
      // 查询参数
      queryParams1: {
        pageNum: 1,
        pageSize: 10,
        caseName: undefined,
        searchKey: undefined,
        caseReason: undefined,
        caseNo: undefined,
        caseType: undefined,
        amount: undefined,
        isProsecutor: undefined,
        isDefendant: undefined,
        judgeResult: undefined,
        judgeDate: undefined,
        publishDate: undefined,
      },
      // 表单参数
      form1: {},
      // 查询参数
      queryParams2: {
        pageNum: 1,
        pageSize: 10,
        judgeId: undefined,
        name: undefined,
        roleType: undefined,
        statement: undefined,
        keyno: undefined,
      },
      // 表单参数
      form2: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    clickOne() {
      if(this.flag == false){
        this.flag = true;
      }else{
        this.flag = false;
      }
    },
    clickDetail(row) {
      this.loading = true;
      this.reset();
      this.queryParams2.judgeId = row.id || this.ids
      getJudgeDetail(this.queryParams2).then(response => {
        this.loading = false;
        this.judgeDetailList = response.rows;
        this.total2 = response.total;
        this.loading = false;
        this.open = true;
        this.title = "当事人信息";
      });
    },
    /** 查询裁判文书信息列表 */
    getList() {
      this.loading = true;
      listJudge(this.queryParams).then(response => {
        this.judgeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getList1() {
      this.loading = true;
      getJudge(this.queryParams1).then(response => {
        this.judgeList1 = response.rows;
        this.total1 = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        judgeId: undefined,
        name: undefined,
        roleType: undefined,
        statement: undefined,
        keyno: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.loading = true;
      searchName(this.queryParams1.caseName).then(response => {
        this.loading = false;
      }).catch(() => {
      }).finally(() => {
        this.$modal.msgSuccess("查询完成,结果如下");
        this.loading = false;
        this.getList1();
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除裁判文书信息编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delJudge(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/judge/export', {
        ...this.queryParams
      }, `judge_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 480px;
  }
</style>